package com.lnt.java.thread.safe;

/**
 * <p>JAVA 在1.5之后加入了LOCK的重量锁</p>
 */
public class TicketSafeLockTest1 {

    private String[] strArray = {"A", "B", "", "", ""};

    private int index = 2;

    public void addStrArray(String str) {
        if (index > 1) {
            strArray[index] = str;
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            index ++;
            System.out.println(Thread.currentThread().getName() + "添加了" + str);
        }
    }

    public String[] getStrArray() {
        return strArray;
    }
}
